import {
  Body,
  Controller,
  Get,
  Post, Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { AudioSynthesisService } from "@/module/audio-synthesis/audio-synthesis.service";
import { UserAuthGuard } from "@/common/auth/user-auth.guard";
import {
  AudioSynthesisBatchDto,
  AudioSynthesisIndexEarbuds2EarbudsDto,
  Earbuds2EarbudsDto
} from "@/module/audio-synthesis/audio-synthesis.dto";
import {
  AudioSynthesisBatchResult,
  AudioSynthesisIndexEarbuds2EarbudsResult,
  GlobalRes,
} from "@/module/audio-synthesis/audio-synthesis.result";
import { User } from "@/common/auth/user.decorator";
import { UserModel } from "@/module/user/user.model";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";
import { PageResult } from "common/interface";
import { getPager } from "@/common/pager-response";

@Controller('/v1/audio-synthesis')
@ApiTags('AudioSynthesis')
@UseGuards(UserAuthGuard)
export class AudioSynthesisV1Controller {
  constructor(private readonly audioSynthesisService: AudioSynthesisService) {
  }

  @Get('/earbuds-2-earbuds')
  @ApiOperation({ summary: '列表查询耳机到耳机' })
  @ApiPaginatedOkResponse(AudioSynthesisIndexEarbuds2EarbudsResult)
  async indexEarbuds2Earbuds(
    @Query() query: AudioSynthesisIndexEarbuds2EarbudsDto,
    @User() user:UserModel,
  ): Promise<PageResult<AudioSynthesisIndexEarbuds2EarbudsResult>> {
    const res = await this.audioSynthesisService.indexEarbuds2Earbuds(query, user.uuid);
    return getPager(res[0], res[1]);
  }

  @Get('/batch')
  @ApiOperation({ summary: '批量查询' })
  @ApiOkResponse({ type: AudioSynthesisBatchResult, isArray: true })
  async batch(
    @Query() query: AudioSynthesisBatchDto,
    @User() user:UserModel,
  ): Promise<AudioSynthesisBatchResult[]> {
    const res = await this.audioSynthesisService.batch(query, user.uuid);
    return res;
  }

  @Post('/earbuds-2-earbuds')
  @ApiOperation({ summary: '耳机到耳机' })
  async earbuds2Earbuds(
    @Body() body: Earbuds2EarbudsDto,
    @User() user: UserModel,
  ): Promise<void> {
    const res = await this.audioSynthesisService.earbuds2Earbuds(body, user.uuid);
    return res;
  }

  @Get('/global')
  @ApiOperation({ summary: '全局数据（轮询）' })
  @ApiOkResponse({ type: GlobalRes })
  async global(
    @User() user: UserModel,
  ): Promise<GlobalRes> {
    const res = await this.audioSynthesisService.global(user.uuid);
    return res;
  }

  /*@Get('/batch-check-status')
  @UseGuards(UserAuthGuard)
  @ApiOperation({ summary: '批量检测状态（轮询）' })
  @ApiOkResponse({ type: BatchCheckStatusResultItem, isArray: true })
  async batchCheckStatus(
    @Query() query: BatchCheckStatusDto,
    @User() user: UserModel,
  ): Promise<BatchCheckStatusResultItem[]> {
    const res = await this.audioSynthesisService.batchCheckStatus(query, user.uuid);
    return res;
  }*/
}
